package ecom.beans;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name = "user")
@NamedQueries({
    @NamedQuery(name = "UserBean.findAll", query = "SELECT u FROM UserBean u"),
    @NamedQuery(name = "UserBean.findByIdUser", query = "SELECT u FROM UserBean u WHERE u.idUser = :idUser"),
    @NamedQuery(name = "UserBean.findByPseudoAndPassword", query = "SELECT u FROM UserBean u WHERE u.pseudo = :pseudo"
    + " and u.password = :password"),
    @NamedQuery(name = "UserBean.findByPseudo", query = "SELECT u FROM UserBean u WHERE u.pseudo = :pseudo"),
    @NamedQuery(name = "UserBean.findByEmail", query = "SELECT u FROM UserBean u WHERE u.email = :email")})
public class UserBean implements Serializable, UserRemote {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_user", nullable = false)
    private Long idUser;
    @Basic(optional = false)
    @Column(name = "pseudo", nullable = false, length = 50, unique = true)
    private String pseudo;
    @Basic(optional = false)
    @Column(name = "password", nullable = false, length = 50)
    private String password;
    @Basic(optional = false)
    @Column(name = "email", nullable = false, length = 50, unique = true)
    private String email;
    @Column(name = "adress", length = 100)
    private String adress;
    @Column(name = "postal_code", length = 10)
    private String postalCode;
    @Column(name = "city", length = 100)
    private String city;
    @Column(name = "country", length = 50)
    private String country;
    @Column(name = "tel", length = 10)
    private String tel;
    @Column(name = "currency", length = 3)
    private String currency;
    @Basic(optional = false)
    @Column(name = "is_admin", nullable = false)
    private boolean isAdmin;
    @JoinColumn(name = "iban", referencedColumnName = "iban", nullable = false)
    @ManyToOne(optional = false)
    private AccountBean account;

    public UserBean() {
    }

    public UserBean(Long idUser) {
        this.idUser = idUser;
    }

    public UserBean(Long idUser, String pseudo, String password, String email, boolean isAdmin) {
        this.idUser = idUser;
        this.pseudo = pseudo;
        this.password = password;
        this.email = email;
        this.isAdmin = isAdmin;
    }

    public UserBean(String pseudo, String password, String email, boolean isAdmin, AccountBean account) {
        this.pseudo = pseudo;
        this.password = password;
        this.email = email;
        this.isAdmin = isAdmin;
        this.account = account;
    }

    public UserBean(String pseudo, String password, String email, String adress, String postalCode, String city, String country, String currency, String tel, boolean isAdmin, AccountBean account) {
        this.pseudo = pseudo;
        this.password = password;
        this.email = email;
        this.adress = adress;
        this.postalCode = postalCode;
        this.city = city;
        this.tel = tel;
        this.isAdmin = isAdmin;
        this.account = account;
        this.country=country;
        this.currency=currency;
    }

    @Override
    public Long getIdUser() {
        return idUser;
    }

    public void setIdUser(Long idUser) {
        this.idUser = idUser;
    }

    @Override
    public String getPseudo() {
        return pseudo;
    }

    public void setPseudo(String pseudo) {
        this.pseudo = pseudo;
    }

    @Override
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }

    @Override
    public String getPostalCode() {
        return postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    @Override
    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    @Override
    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    @Override
    public boolean getIsAdmin() {
        return isAdmin;
    }

    public void setIsAdmin(boolean isAdmin) {
        this.isAdmin = isAdmin;
    }

    @Override
    public AccountBean getAccount() {
        return account;
    }

    public void setAccount(AccountBean iban) {
        this.account = iban;
    }

    @Override
    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }
    
    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idUser != null ? idUser.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UserBean)) {
            return false;
        }
        UserBean other = (UserBean) object;
        if ((this.idUser == null && other.idUser != null) || (this.idUser != null && !this.idUser.equals(other.idUser))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "[idUser=" + idUser + ",pseudo=" + pseudo + ",password=" + password
                + ",email=" + email + ",adress" + adress
                + ",postalCode=" + postalCode + ",city=" + city + ",tel=" + tel
                + ",currency=" + currency + ",isAdmin=" + isAdmin + ",iban="
                + account.getIban() + ",balance=" + account.getBalance() + "]";
    }
}
